package com.mch.func.file.html;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Insets;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.mch.biz.ui.BizEvent;
import org.mch.biz.ui.BizPanel;
import org.mch.swingm.core.MTextField;

public class HTMLFilePanel extends BizPanel {
	private static final long serialVersionUID = 1L;
	private JSplitPane splitPane;
	private JPanel panel;
	private JPanel panel_right;
	private JScrollPane scrollPane;
	private RSyntaxTextArea textarea;
	private JButton btn_html_lower;
	private JButton btn_file;
	private JScrollPane scrollPane_2;
	private JTextArea text_file;
	private JComboBox<String> combo_encode;
	private MTextField text_filetype;

	public HTMLFilePanel() {
		initComponents();
	}

	private void initComponents() {
		setLayout(new BorderLayout(0, 0));
		add(getSplitPane(), "Center");
	}

	public JSplitPane getSplitPane() {
		if (this.splitPane == null) {
			this.splitPane = new JSplitPane();
			splitPane.setDividerSize(5);
			this.splitPane.setLeftComponent(getPanel());
			this.splitPane.setRightComponent(getPanel_right());
			this.splitPane.setDividerLocation(300);
		}
		return this.splitPane;
	}

	public JPanel getPanel() {
		if (this.panel == null) {
			this.panel = new JPanel();
			this.panel.setLayout(null);
			panel.add(getBtn_html_lower());
			panel.add(getBtn_file());
			panel.add(getScrollPane_2());
			panel.add(getCombo_encode());
			panel.add(getText_filetype());
		}
		return this.panel;
	}

	public JPanel getPanel_right() {
		if (this.panel_right == null) {
			this.panel_right = new JPanel();
			this.panel_right.setLayout(new BorderLayout(0, 0));
			panel_right.add(getScrollPane(), BorderLayout.CENTER);
		}
		return this.panel_right;
	}

	public JScrollPane getScrollPane() {
		if (this.scrollPane == null) {
			this.scrollPane = new JScrollPane();
			this.scrollPane.setViewportView(getTextarea());
		}
		return this.scrollPane;
	}

	public RSyntaxTextArea getTextarea() {
		if (this.textarea == null) {
			this.textarea = new RSyntaxTextArea();
			this.textarea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSP);
			this.textarea.setFont(new Font("宋体", Font.PLAIN, 13));
			this.textarea.setBorder(new SoftBevelBorder(1, null, null, null, null));
		}
		return this.textarea;
	}

	protected BizEvent createEvent() {
		return new HTMLFileEvent(this);
	}

	public JButton getBtn_html_lower() {
		if (btn_html_lower == null) {
			btn_html_lower = new JButton("转换小写");
			btn_html_lower.setMargin(new Insets(0, 0, 0, 0));
			btn_html_lower.setFont(new Font("宋体", Font.PLAIN, 12));
			btn_html_lower
					.setToolTipText("将选择的文件中的标签转换为小写输出到右边文本框中，如果选择的文件夹则将整个文件夹下内容的标签转换为小写输出到平级加_low文件中");
			btn_html_lower.setBounds(195, 110, 92, 26);
			btn_html_lower.addMouseListener(getEvent());
		}
		return btn_html_lower;
	}

	public JButton getBtn_file() {
		if (btn_file == null) {
			btn_file = new JButton("...");
			btn_file.setBounds(246, 12, 41, 48);
			btn_file.addMouseListener(getEvent());
		}
		return btn_file;
	}

	public JScrollPane getScrollPane_2() {
		if (scrollPane_2 == null) {
			scrollPane_2 = new JScrollPane();
			scrollPane_2.setBorder(new LineBorder(Color.LIGHT_GRAY));
			scrollPane_2.setBounds(12, 12, 234, 48);
			scrollPane_2.setViewportView(getText_file());
		}
		return scrollPane_2;
	}

	public JTextArea getText_file() {
		if (text_file == null) {
			text_file = new JTextArea();
			text_file.setFont(new Font("宋体", Font.PLAIN, 13));
		}
		return text_file;
	}

	public JComboBox<String> getCombo_encode() {
		if (combo_encode == null) {
			combo_encode = new JComboBox<String>();
			combo_encode.setForeground(Color.RED);
			combo_encode.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			combo_encode.setFont(new Font("宋体", Font.BOLD, 13));
			combo_encode.setModel(new DefaultComboBoxModel<String>(new String[] { "GBK", "UTF-8" }));
			combo_encode.setBounds(12, 110, 68, 26);
		}
		return combo_encode;
	}

	public MTextField getText_filetype() {
		if (text_filetype == null) {
			text_filetype = new MTextField();
			text_filetype.setToolTipText("处理文件的后缀");
			text_filetype.setFont(new Font("宋体", Font.PLAIN, 13));
			text_filetype.setText("html,HTML,htm,HTM,JSP,jsp");
			text_filetype.setBounds(12, 72, 275, 26);
			text_filetype.setColumns(10);
		}
		return text_filetype;
	}
}